import os, sys
import subprocess
from subprocess import Popen

if __name__ == '__main__' :
    process_list = []
    num_procs = int(sys.argv[1])
    if sys.argv[2] != None:
        file_size = "_" + sys.argv[2]
    else:
        file_size = ""
    request_rate = 0
    xput = 0
    request_rate_agg = 0
    for j in range(0,6):
        for i in range(0,num_procs):
            process_list.append(Popen(["python", "webserver.py", "%d"%i, "%s"%file_size]))
        for i in range(0,num_procs):
            process_list[i].wait()
            input_file = open("tmp_data/output%d"%i, 'r')
            strings = input_file.readlines()
            request_rate += float(strings[1])
            xput += float(strings[0])
        process_list = []
        print "%.02f"%request_rate
        request_rate_agg += request_rate
        request_rate = 0

    final_rate = request_rate_agg / 6
    print "%.02f Kr/s"%final_rate
        


